<?php
$start  = microtime(true);
$mysqli = new mysqli("localhost", "root", "123456", "test");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* create a prepared statement */
$stmt =  $mysqli->stmt_init();

if ($stmt->prepare("SELECT username FROM test2 WHERE id = ?")) {

    for ($i = 1; $i < 10; $i++)
    {
        /* bind parameters for markers */
        $stmt->bind_param("i", $i);

        /* execute query */
        $stmt->execute();

        /* bind result variables */
        $stmt->bind_result($name);

        /* fetch value */
        $stmt->fetch();

        printf("User ID %s has got a name %s\n", $i, $name);
        echo '<br />';
        $stmt->free_result();
        $stmt->reset();
    }

    echo microtime(true) - $start. ' seconds <br />';

    /* close statement */
    $stmt->close();
}

/* close connection */
$mysqli->close();
?>
